import gevent


def f1(n):
    for i in range(n):
        print("------f1------")
        # print(gevent.getcurrent(), i)
        gevent.sleep(0.5)


def f2(n):
    for i in range(n):
        print("------f2------")
        # print(gevent.getcurrent(), i)


def f3(n):
    for i in range(n):
        print("------f3------")
        # print(gevent.getcurrent(), i)


g1 = gevent.spawn(f1, 5)
g2 = gevent.spawn(f2, 6)
g3 = gevent.spawn(f3, 7)

# 当有延时操作时，已经开始进行切换协程了
gevent.sleep(1)

# 之所以不用延时，而是用join，这就保证了一定等到g1标记的协议对象一定运行完毕，同理g2、g3
# g1.join()
# g2.join()
# g3.join()
